package com.kasax.basiclib;

import android.view.View;

import java.util.WeakHashMap;

public class ClickDebouncer {
    private static final long DEFAULT_DEBOUNCE_INTERVAL = 300L; // 300ms防抖间隔
    private static final WeakHashMap<View, Long> lastClickMap = new WeakHashMap<>();
    
    public static boolean shouldHandleClick(View view) {
        if (view == null) return true;
        
        long currentTime = System.currentTimeMillis();
        Long lastClickTime = lastClickMap.get(view);
        
        if (lastClickTime == null || currentTime - lastClickTime > DEFAULT_DEBOUNCE_INTERVAL) {
            lastClickMap.put(view, currentTime);
            return true;
        }
        
        return false;
    }
    
    // 可配置防抖间隔
    public static void setDebounceInterval(long intervalMs) {
        // 可在Application中配置
    }
}